﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using NicoView.Speech;
using GalaSoft.MvvmLight.Messaging;
using System.Threading.Tasks;

namespace NicoView.View.Behaviors
{
    //
    // Action のターゲット要素をその親以外にしたい場合、クラスを
    // TriggerAction の代わりに TargetedTriggerAction から拡張します
    //
    public class NotificationAction : TriggerAction<MainWindow>
    {
        public NotificationAction()
        {

        }

        protected override async void Invoke(object msg)
        {
            var message = msg as NotificationMessage;

            lock (this.AssociatedObject.NotifyStatus)
            {
                this.AssociatedObject.NotifyStatus.Content = message.Notification;
            }
            
            await Task.Delay(TimeSpan.FromSeconds(7));

            lock (this.AssociatedObject.NotifyStatus)
            {
                if ((string)this.AssociatedObject.NotifyStatus.Content == message.Notification)
                {
                    this.AssociatedObject.NotifyStatus.Content = "";
                }
            }
        }
    }
}